import { h, render } from "vue";
import Start from "./Start.vue";

export default function registerSection(lf) {
  lf.register("start", ({ HtmlNode, HtmlNodeModel }) => {
    class ConnectNode extends HtmlNode {
      setHtml(rootEl) {
        const el = document.createElement("div");
        rootEl.innerHTML = "";
        const Profile = h(Start);
        render(Profile, el);
        rootEl.appendChild(el);
      }
    }
    class ConnectNodeModel extends HtmlNodeModel {
      setAttributes() {
        this.menu = [];
      }
      initNodeData(data) {
        data.text = {
          editable: false,
        };
        super.initNodeData(data);
        const width = 100;
        const height = 40;
        this.width = width;
        this.height = height;
      }
      getConnectedTargetRules() {
        const rules = super.getConnectedTargetRules();
        const addRules = {
          message: "开始节点只能连出，不能连入！",
          validate: () => false,
        };
        rules.push(addRules);
        return rules;
      }
    }
    return {
      type: "section",
      view: ConnectNode,
      model: ConnectNodeModel,
    };
  });
}
